<?php

/*
	This file is part of Mandragon.

    Mandragon is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Mandragon is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Mandragon.  If not, see <http://www.gnu.org/licenses/>.
*/

require_once 'PHPUnit/Framework.php';
require_once 'autoload.php';

class TestWebLink extends PHPUnit_Framework_TestCase {
	
	function test_prepare() {
		$expected_item_link = 'item_link';
		$expected_item_body = 'item_body';
		$expected_desqlized_item_link = 'desqlized_item_link';
		$expected_desqlized_item_body = 'desqlized_item_body';
		$expected_link_input = 'link_input';
		$expected_body_input = 'body_input';
		$expected_item = array('link' => $expected_item_link,
				'body' => $expected_item_body);
		$expected_inputs = array($expected_link_input, $expected_body_input);

		$page = new Page();
		$link = new WebLink($page);

		$mock_db_access = $this->getMock('DbAccessor');
		$mock_db_access->expects($this->at(0))
				->method('db_desqlize')
				->with($expected_item_link)
				->will($this->returnValue($expected_desqlized_item_link));
		$mock_db_access->expects($this->at(1))
				->method('db_desqlize')
				->with($expected_item_body)
				->will($this->returnValue($expected_desqlized_item_body));
		$link->set_db_accessor($mock_db_access);

		$mock_creator = $this->getMock('FormCreator');
		$mock_creator->expects($this->once())
				->method('input_field')
				->with("Link", "link", $expected_desqlized_item_link)
				->will($this->returnValue($expected_link_input));
		$mock_creator->expects($this->once())
				->method('input_text')
				->with("Beschrijving", "body", $expected_desqlized_item_body)
				->will($this->returnValue($expected_body_input));
		$link->set_form_creator($mock_creator);

		$actual = $link->prepare(false, $expected_item, null);
		$this->assertEquals($expected_inputs, $actual);
	}
}
